class Order {
    constructor(store, options) {
        this.store = store;
        this.options = options;
        this.install();
        return this;
    }
    install() {
        this.store.registerModule(["order"], this.options.data());
        let obj = this.options.mixin();
        for (let n in obj) {
            if (n !== "data") this[n] = obj[n];
        }
        return this;
    }
    uninstall() {
        this.store.unregisterModule(["order"]);
        return this;
    }
}

export const order = function(Vue, store) {
    return new Promise((resolve, reject) => {
        try {
            Vue.prototype.$order = Vue.$order = new Order(store, {
                data() {
                    return {
                        state: {},
                        actions: {
                            getWorkOrderList(store, json) {
                                return new Promise((resolve, reject) => {
                                    store
                                        .dispatch("requestData", {
                                            path: "/getWorkOrderList",
                                            data: json,
                                        })
                                        .then((v) => {
                                            resolve(v);
                                        })
                                        .catch((v) => {
                                            reject(v);
                                        });
                                });
                            },
                            examineSelectedOrders(store, json) {
                                return new Promise((resolve, reject) => {
                                    store
                                        .dispatch("requestData", {
                                            path: "/examineSelectedOrders",
                                            data: json,
                                        })
                                        .then((v) => {
                                            resolve(v);
                                        })
                                        .catch((v) => {
                                            reject(v);
                                        });
                                });
                            },
                            execSelectedOrders(store, json) {
                                return new Promise((resolve, reject) => {
                                    store
                                        .dispatch("requestData", {
                                            path: "/execSelectedOrders",
                                            data: json,
                                        })
                                        .then((v) => {
                                            resolve(v);
                                        })
                                        .catch((v) => {
                                            reject(v);
                                        });
                                });
                            },
                            deleteSelectedOrders(store, json) {
                                return new Promise((resolve, reject) => {
                                    store
                                        .dispatch("requestData", {
                                            path: "/deleteSelectedOrders",
                                            data: json,
                                        })
                                        .then((v) => {
                                            resolve(v);
                                        })
                                        .catch((v) => {
                                            reject(v);
                                        });
                                });
                            },
                        },
                        mutations: {},
                    };
                },
                mixin() {
                    return {
                        getWorkOrderList(json) {
                            return this.store.dispatch("getWorkOrderList", json);
                        },
                        examineSelectedOrders(json) {
                            return this.store.dispatch("examineSelectedOrders", json);
                        },
                        execSelectedOrders(json) {
                            return this.store.dispatch("execSelectedOrders", json);
                        },
                        deleteSelectedOrders(json) {
                            return this.store.dispatch("deleteSelectedOrders", json);
                        },
                    };
                },
            });
            resolve(Vue);
        } catch (e) {
            reject(e);
        }
    });
};